Partial Class pages_Scribes_Scribe : Inherits CPage

#Region "Querystring"
    Public ReadOnly Property ScribeId() As Byte
        Get
            Return CWeb.RequestByte("scribeId")
        End Get
    End Property
    Public ReadOnly Property IsEdit() As Boolean
        Get
            Return ScribeId <> Integer.MinValue
        End Get
    End Property
#End Region

#Region "Members"
    Private m_scribe As CScribe
#End Region

#Region "Data"
    Public ReadOnly Property [Scribe]() As CScribe
        Get
            If IsNothing(m_scribe) Then
                If IsEdit Then
                    m_scribe = CScribe.Cache.GetById(ScribeId)
                    If IsNothing(m_scribe) Then CSitemap.RecordNotFound("Scribe", ScribeId)
                Else
                    m_scribe = New CScribe
                    'Inserts: set parentId here (if applicable)
                End If
            End If
            Return m_scribe
        End Get
    End Property
#End Region

#Region "Navigation"
    Private Sub Refresh()
        Response.Redirect(CSitemap.ScribeEdit(Me.Scribe.ScribeId))
    End Sub
    Private Sub ReturnToList()
        Response.Redirect(CSitemap.Scribes)
    End Sub
#End Region

#Region "Event Handlers - Page"
    Protected Overrides Sub PageInit()

        'Page Title
        If IsEdit Then            
            Me.Title = "Scribe Details"
        Else
            Me.Title = "Create New Scribe"
        End If
                
        'Textbox logic
        'Me.Form.DefaultFocus = txtScribeName.Textbox.ClientID;
        Me.Form.DefaultButton = btnSave.UniqueID   'txtScribeName.OnReturnPress(btnSave)

        'Button Text
        btnDelete.Visible = IsEdit
        If IsEdit Then btnCancel.Text = "Back" Else btnSave.Text = "Create Scribe"
        If IsEdit Then AddButton(CSitemap.ScribeAdd(), "Create a new Scribe")
    End Sub
    Protected Overrides Sub PageLoad()
        If Page.IsPostback Then Exit Sub

        LoadScribe()
    End Sub
#End Region

#Region "Event Handlers - Form"
    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Not Me.IsValid() Then Exit Sub
        SaveScribe()
        Refresh()
    End Sub
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        ReturnToList()
    End Sub
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Me.Scribe.Delete()
            'CCache.ClearCache()
        ReturnToList()        
    End Sub
#End Region

#Region "Private - Load/Save"
    Protected Sub LoadScribe()
        With Me.Scribe
            txtScribeDisplayName.Text = .ScribeDisplayName
            txtScribeDisplayWebsite.Text = .ScribeDisplayWebsite
            txtScribeContactName.Text = .ScribeContactName
            txtScribeContactEmail.Text = .ScribeContactEmail
            txtScribeContactPhone.Text = .ScribeContactPhone
            txtScribeBankAccount.Text = .ScribeBankAccount
            chkScribeForText.Checked = .ScribeForText
            chkScribeForImages.Checked = .ScribeForImages
        End With
    End Sub
    Protected Sub SaveScribe()
        With Me.Scribe
            .ScribeDisplayName = txtScribeDisplayName.Text
            .ScribeDisplayWebsite = txtScribeDisplayWebsite.Text
            .ScribeContactName = txtScribeContactName.Text
            .ScribeContactEmail = txtScribeContactEmail.Text
            .ScribeContactPhone = txtScribeContactPhone.Text
            .ScribeBankAccount = txtScribeBankAccount.Text
            .ScribeForText = chkScribeForText.Checked
            .ScribeForImages = chkScribeForImages.Checked

            .Save()
        End With
            'CCache.ClearCache()
    End Sub
#End Region


End Class
